#region license
# This file is part of Grawlix.
# 
# Grawlix is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# 
# Grawlix is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with Grawlix.  If not, see
# <http://www.gnu.org/licenses/>.
#endregion

"""The default <ITypedResolver[of T]> implementation for Bitmaps."""

namespace Grawlix.Services.Resources
import Grawlix
import System

transient class ImageResolver(TypedResolverBase[of Image]):
"""A service that resolves URIs into Bitmaps."""
	
	def constructor(
		streamResolver as IStreamResolver,
		embeddedResolver as IEmbeddedResolver,
		uriResolver as IUriResolver):
	"""
	Initializes a new embedded resolver.
	Param streamResolver: The URI-to-stream translator.
	Param embeddedResolver: The URI-to-embedded resource translator.
	Param uriResolver: The URI translator.
	"""
		super(streamResolver, embeddedResolver, uriResolver)
	
	protected override def LoadFromStream([required] stream as IO.Stream):
	"""
	Load a specified object from stream.
	Param stream: The stream to load from.
	Returns: The represented object, or null.
	"""
		return Image(stream)
	
	protected override def LoadFromEmbeddedResource(
		[required] embeddedResource):
	"""
	Loads from an embedded resource.
	Param embeddedResource: The untyped resource to load.
	Returns: The loaded object, or null.
	"""
		imageObject = embeddedResource as Drawing.Image
		return Image(imageObject) unless imageObject is null
		return super(embeddedResource)
	
	override def ToString():
	"""
	Get a string representation for this object.
	Returns: A string representation for this object.
	"""
		return "ImageResolver"
	
